package com.yuzhi.master.system;

import com.yuzhi.common.annotation.Log;
import com.yuzhi.common.annotation.RepeatSubmit;
import com.yuzhi.common.core.controller.BaseController;
import com.yuzhi.common.core.domain.ApiResult;
import com.yuzhi.common.core.page.PageDataInfo;
import com.yuzhi.common.core.validate.AddGroup;
import com.yuzhi.common.core.validate.EditGroup;
import com.yuzhi.common.enums.BusinessTypeEnum;
import com.yuzhi.common.util.poi.ExcelUtil;

import com.yuzhi.master.system.domain.SysBasicInfoBo;
import com.yuzhi.master.system.request.SysBasicInfoReq;
import com.yuzhi.master.system.service.ISysBasicInfoService;
import com.yuzhi.master.system.vo.SysBasicInfoVo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 系统基础信息
 *
 * @author auto code generator
 * @date 2024-04-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/basicInfo")
public class SysBasicInfoController extends BaseController {

    private final ISysBasicInfoService iSysBasicInfoService;

    /**
     * 查询系统基础信息列表
     */
    //@SaCheckPermission("system:basicInfo:list")
    @PostMapping("/list")
    public ApiResult<PageDataInfo> list(@RequestBody SysBasicInfoReq request) {
        return ApiResult.ok(iSysBasicInfoService.queryPageList(request));
    }

    /**
     * 导出系统基础信息列表
     */
    //@SaCheckPermission("system:basicInfo:export")
    @Log(title = "系统基础信息", businessType = BusinessTypeEnum.EXPORT)
    @PostMapping("/export")
    public void export(@RequestBody SysBasicInfoReq bo, HttpServletResponse response) {
        List<SysBasicInfoVo> list = iSysBasicInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "系统基础信息", SysBasicInfoVo.class, response);
    }

    /**
     * 获取系统基础信息详细信息
     *
     * @param orgCode 主键
     */
    //@SaCheckPermission("system:basicInfo:query")
    @GetMapping("/{orgCode}")
    public ApiResult<SysBasicInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String orgCode) {
        return ApiResult.ok(iSysBasicInfoService.queryById(orgCode));
    }

    /**
     * 新增系统基础信息
     */
    //@SaCheckPermission("system:basicInfo:add")
    @Log(title = "系统基础信息", businessType = BusinessTypeEnum.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public ApiResult<Void> add(@Validated(AddGroup.class) @RequestBody SysBasicInfoBo bo) {
        return toAjax(iSysBasicInfoService.insertByBo(bo));
    }

    /**
     * 修改系统基础信息
     */
    //@SaCheckPermission("system:basicInfo:edit")
    @Log(title = "系统基础信息", businessType = BusinessTypeEnum.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public ApiResult<SysBasicInfoBo> edit(@Validated(EditGroup.class) @RequestBody SysBasicInfoBo bo) {
        Boolean b = iSysBasicInfoService.updateByBo(bo);
        return ApiResult.ok(bo);
    }

    /**
     * 删除系统基础信息
     *
     * @param orgCodes 主键串
     */
    ///@SaCheckPermission("system:basicInfo:remove")
    @Log(title = "系统基础信息", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{orgCodes}")
    public ApiResult<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] orgCodes) {
        return toAjax(iSysBasicInfoService.deleteWithValidByIds(Arrays.asList(orgCodes), true));
    }
}
